package com.liqin.nothing.result;

import org.springframework.http.HttpStatus;

public class R {



    public static <T> Response<T> of(T data){
        return of(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
    }

    public static <T> Response<T> of(Integer code, String msg){
        return of(code, msg, null);
    }

    public static <T> Response<T> of(Integer code, String msg, T data){
        Response<T> response = new Response<T>();
        response.setCode(code);
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    public static <T> Response<T> success(){
        Response<T> response = new Response<T>();
        response.setCode(HttpStatus.OK.value());
        response.setMsg(HttpStatus.OK.getReasonPhrase());
        return response;
    }

    public static <T> Response<T> success(String msg){
        Response<T> response = new Response<T>();
        response.setCode(HttpStatus.OK.value());
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> success(T t){
        Response<T> response = new Response<T>();
        response.setCode(HttpStatus.OK.value());
        response.setMsg(HttpStatus.OK.getReasonPhrase());
        response.setData(t);
        return response;
    }

    public static <T> Response<T> fail(){
        Response<T> response = new Response<T>();
        response.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.setMsg("服务器错误");
        return response;
    }

    public static <T> Response<T> fail(HttpStatus status){
        Response<T> response = new Response<T>();
        response.setCode(status.value());
        response.setMsg(status.getReasonPhrase());
        return response;
    }

    public static <T> Response<T> fail(HttpStatus status, String msg){
        Response<T> response = new Response<T>();
        response.setCode(status.value());
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> fail(String msg, T data){
        Response<T> response = new Response<T>();
        response.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    public static <T> Response<T> fail(String msg){
        Response<T> response = new Response<T>();
        response.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> fail(int code, String msg){
        Response<T> response = new Response<T>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> fail(int code, String msg, T data){
        Response<T> response = new Response<T>();
        response.setCode(code);
        response.setMsg(msg);
        response.setData(data);
        return response;
    }
}
